package com.youhong.teethcare.javabeans;


import android.content.Context;

import com.youhong.teethcare.utils.PreferencesUtils;
import com.youhong.teethcare.utils.Util;

import java.util.Calendar;


/**
 * Created by Administrator on 2017/5/16.
 */

public class UserInfo {

    public static final String PREF_TOKEN = "TOKEN";
    public static final String PREF_NICKNAME = "user_Nickname";
    public static final String PREF_SEX = "user_Sex";
    public static final String PREF_BIRTHDAY = "user_Birthday";
    public static final String PREF_HEADURL = "_user_HeadUrl";
    public static final String PREF_LAST_SYNC_TIME = "_LAST_SYNC_TIME";
    public static final String PREF_DRINKING_NOTIFICATION = "_DRINKING_NOTIFICATION";
    public static final String PREF_DEVICE_NAME = "_DEVICE_NAME";
    public static final String PREF_DEVICE_BATTERY = "_DEVICE_BATTERY";
    public static final String PREF_DEVICE_Version = "_DEVICE_Version";
    public static final String PREF_MAC = "_MAC";
    public static final String PREF_HAND = "_HAND";
    public static final String PREF_MANNER = "_MANNER";

    public static final String PREF_CONDITION = "_CONDITION";
    public static final String PREF_NOTIFICATION_CLOCK1_SWITCH = "_NOTIFICATION_CLOCK1_SWITCH";
    public static final String PREF_NOTIFICATION_CLOCK1_TIME = "_NOTIFICATION_CLOCK1_TIME";
    public static final String PREF__NOTIFICATION_CLOCK1_DAY_OF_WEEK = "_NOTIFICATION_CLOCK1_DAY_OF_WEEK";
    public static final String PREF_NOTIFICATION_CLOCK2_SWITCH = "_NOTIFICATION_CLOCK2_SWITCH";
    public static final String PREF_NOTIFICATION_CLOCK2_TIME = "_NOTIFICATION_CLOCK2_TIME";
    public static final String PREF__NOTIFICATION_CLOCK2_DAY_OF_WEEK = "_NOTIFICATION_CLOCK2_DAY_OF_WEEK";
    public static final String PREF_NOTIFICATION_CLOCK3_SWITCH = "_NOTIFICATION_CLOCK3_SWITCH";
    public static final String PREF_NOTIFICATION_CLOCK3_TIME = "_NOTIFICATION_CLOCK3_TIME";
    public static final String PREF__NOTIFICATION_CLOCK3_DAY_OF_WEEK = "_NOTIFICATION_CLOCK3_DAY_OF_WEEK";
    public static final String PREF_NOTIFICATION_CLOCK4_SWITCH = "_NOTIFICATION_CLOCK4_SWITCH";
    public static final String PREF_NOTIFICATION_CLOCK4_TIME = "_NOTIFICATION_CLOCK4_TIME";
    public static final String PREF__NOTIFICATION_CLOCK4_DAY_OF_WEEK = "_NOTIFICATION_CLOCK4_DAY_OF_WEEK";
    public static final String PREF_FIRST_TIME_IN_APP = "_NOTIFICATION_FIRST_TIME_IN_APP";
    public static final String PREF_BRUSH_TIME = "_NOTIFICATION_BRUSH_TIME";
    public static final String PREF_SCORE = "_SCORE";
    public static final String PREF_CHANGE_HEAD = "_CHANGE_HEAD";
    public static final String PREF_COLLECT_LOG = "_COLLECT_LOG";
    public static final String PREF_TEETH_WHITENESS = "TEETH_WHITENESS";
    public static final String PREF_IS_FIRST_TIME_DISPLAY_PAQUE = "_IS_FIRST_TIME_DISPLAY_PAQUE";
    public static final String PREF_Psd = "Psd";
    public static final String PREF_AreaCode = "AreaCode";
    public static final String PREF_Account = "Account";
    public static final String PREF_isRememberPassword = "isRememberPassword";
    public static final String PREF_LastLoginType= "PREF_LastLoginType";

    public String getPsd() {
        return Psd;
    }

    public void setPsd(String psd) {
        Psd = psd;
    }

    public String getAreaCode() {
        return AreaCode;
    }

    public void setAreaCode(String areaCode) {
        AreaCode = areaCode;
    }

    public String getAccount() {
        return Account;
    }

    public void setAccount(String account) {
        Account = account;
    }

    public   String Psd = "";
    public   String AreaCode = "";
    public   String Account = "";
    public int lastLoginType;

    public int getLastLoginType() {
        return lastLoginType;
    }

    public void setLastLoginType(int lastLoginType) {
        this.lastLoginType = lastLoginType;
    }

    public boolean isRememberPassword() {
        return isRememberPassword;
    }

    public void setRememberPassword(boolean rememberPassword) {
        isRememberPassword = rememberPassword;
    }

    boolean isRememberPassword=false;
    public int getTeethWhiteness() {
        return teethWhiteness;
    }

    public void setTeethWhiteness(int teethWhiteness) {
        this.teethWhiteness = teethWhiteness;
    }

    //实际上是SwitchBar 的leftMargin值
    int teethWhiteness = 0;

    public boolean getCollectLog() {
        return collectLog;
    }

    public void setCollectLog(boolean collectLog) {
        this.collectLog = collectLog;
    }

    private boolean collectLog;

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    private int score;

    public int getBrushTime() {
        return brushTime;
    }

    public void setBrushTime(int brushTime) {
        this.brushTime = brushTime;
    }

    private int brushTime;

    public long getChangeHead() {
        return changeHead;
    }

    public void setChangeHead(long changeHead) {
        this.changeHead = changeHead;
    }

    private long changeHead;

    private boolean clockSwitch1;
    private String clockTime1;
    private int clockDayOfWeek1;

    public boolean isFirstTimeIntoAPP() {
        return isFirstTimeIntoAPP;
    }

    public void setFirstTimeIntoAPP(boolean firstTimeIntoAPP) {
        isFirstTimeIntoAPP = firstTimeIntoAPP;
    }

    private boolean isFirstTimeIntoAPP;

    private boolean clockSwitch2;

    public boolean isClockSwitch1() {
        return clockSwitch1;
    }

    public void setClockSwitch1(boolean clockSwitch1) {
        this.clockSwitch1 = clockSwitch1;
    }

    public String getClockTime1() {
        return clockTime1;
    }

    public void setClockTime1(String clockTime1) {
        this.clockTime1 = clockTime1;
    }

    public int getClockDayOfWeek1() {
        return clockDayOfWeek1;
    }

    public void setClockDayOfWeek1(int clockDayOfWeek1) {
        this.clockDayOfWeek1 = clockDayOfWeek1;
    }

    public boolean isClockSwitch2() {
        return clockSwitch2;
    }

    public void setClockSwitch2(boolean clockSwitch2) {
        this.clockSwitch2 = clockSwitch2;
    }

    public String getClockTime2() {
        return clockTime2;
    }

    public void setClockTime2(String clockTime2) {
        this.clockTime2 = clockTime2;
    }

    public int getClockDayOfWeek2() {
        return clockDayOfWeek2;
    }

    public void setClockDayOfWeek2(int clockDayOfWeek2) {
        this.clockDayOfWeek2 = clockDayOfWeek2;
    }

    public boolean isClockSwitch3() {
        return clockSwitch3;
    }

    public void setClockSwitch3(boolean clockSwitch3) {
        this.clockSwitch3 = clockSwitch3;
    }

    public String getClockTime3() {
        return clockTime3;
    }

    public void setClockTime3(String clockTime3) {
        this.clockTime3 = clockTime3;
    }

    public int getClockDayOfWeek3() {
        return clockDayOfWeek3;
    }

    public void setClockDayOfWeek3(int clockDayOfWeek3) {
        this.clockDayOfWeek3 = clockDayOfWeek3;
    }

    public boolean isClockSwitch4() {
        return clockSwitch4;
    }

    public void setClockSwitch4(boolean clockSwitch4) {
        this.clockSwitch4 = clockSwitch4;
    }

    public String getClockTime4() {
        return clockTime4;
    }

    public void setClockTime4(String clockTime4) {
        this.clockTime4 = clockTime4;
    }

    public int getClockDayOfWeek4() {
        return clockDayOfWeek4;
    }

    public void setClockDayOfWeek4(int clockDayOfWeek4) {
        this.clockDayOfWeek4 = clockDayOfWeek4;
    }

    private String clockTime2;
    private int clockDayOfWeek2;

    private boolean clockSwitch3;
    private String clockTime3;
    private int clockDayOfWeek3;

    private boolean clockSwitch4;
    private String clockTime4;
    private int clockDayOfWeek4;

    private String token;
    private String nickName;
    private int gender;
    private Calendar birthday;
    private String headUrl;

    //0:Right, 1:left
    private int hand;

    //bitmap: bit0:喝咖啡,bit1:喝茶,bit2:喝红酒,bit3s:抽烟, all clear: NONE
    private int manner;
    //0:健康,1:敏感,2:牙龈出血,3:牙齿发黄
    private int condition;

    private String deviceName;

    public String getDeviceVersion() {
        return deviceVersion;
    }

    public void setDeviceVersion(String deviceVersion) {
        this.deviceVersion = deviceVersion;
    }

    private String deviceVersion="--";
    private int deviceBattery;

    private long lastSyncTime;
    private boolean drinkingNotification;
    private String mac;

    public boolean isFirstTimeDisplayPlaque() {
        return isFirstTimeDisplayPlaque;
    }

    public void setFirstTimeDisplayPlaque(boolean firstTimeDisplayPlaque) {
        isFirstTimeDisplayPlaque = firstTimeDisplayPlaque;
    }

    private boolean isFirstTimeDisplayPlaque;


    public int getManner() {
        return manner;
    }

    public void setManner(int manner) {
        this.manner = manner;
    }

    public int getCondition() {
        return condition;
    }

    public void setCondition(int condition) {
        this.condition = condition;
    }

    public long getLastSyncTime() {
        return lastSyncTime;
    }

    public void setLastSyncTime(long lastSyncTime) {
        this.lastSyncTime = lastSyncTime;
    }


    public boolean getDrinkingNotification() {
        return drinkingNotification;
    }

    public void setDrinkingNotification(boolean drinkingNotification) {
        this.drinkingNotification = drinkingNotification;
    }


    public String getMac() {
        return mac;
    }

    public void setMac(String mac) {
        this.mac = mac;
    }


    public String getDeviceName() {
        return deviceName;
    }

    public void setDeviceName(String deviceName) {
        this.deviceName = deviceName;
    }

    public int getDeviceBattery() {
        return deviceBattery;
    }

    public void setDeviceBattery(int deviceBattery) {
        this.deviceBattery = deviceBattery;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public int getGender() {
        return gender;
    }

    public void setGender(int gender) {
        this.gender = gender;
    }

    public Calendar getBirthday() {
        return birthday;
    }

    public void setBirthday(Calendar birthday) {
        this.birthday = birthday;
    }

    public String getHeadUrl() {
        return headUrl;
    }

    public void setHeadUrl(String headUrl) {
        this.headUrl = headUrl;
    }

    public int getHand() {
        return hand;
    }

    public void setHand(int hand) {
        this.hand = hand;
    }

    public static UserInfo getUserInfoFromSharedPreferences(Context context) {

        /*if (PreferencesUtils.ReadFromPreferencesString(context, PREF_TOKEN) == "") {

            return null;
        }*/
        UserInfo userInfo = new UserInfo();

        userInfo.token = PreferencesUtils.ReadFromPreferencesString(context, PREF_TOKEN);
        userInfo.nickName = PreferencesUtils.ReadFromPreferencesString(context, PREF_TOKEN + PREF_NICKNAME);
        //1:Male 2:Female
        userInfo.gender = PreferencesUtils.ReadFromPreferencesInt(context, userInfo.token + PREF_SEX);
        userInfo.birthday = Util.analyzeDateString2(PreferencesUtils.ReadFromPreferencesString(context, userInfo.token + PREF_BIRTHDAY));
        userInfo.headUrl = PreferencesUtils.ReadFromPreferencesString(context, userInfo.token + PREF_HEADURL);
        userInfo.mac = PreferencesUtils.ReadFromPreferencesString(context, userInfo.token + PREF_MAC);
        //DrinkNotification 1:disable 0:enable;
        userInfo.drinkingNotification = PreferencesUtils.ReadFromPreferencesBoolean(context, userInfo.token + PREF_DRINKING_NOTIFICATION);
        userInfo.isFirstTimeIntoAPP = PreferencesUtils.ReadFromPreferencesBoolean(context, userInfo.token + PREF_FIRST_TIME_IN_APP);

        userInfo.deviceName = PreferencesUtils.ReadFromPreferencesString(context, userInfo.token + PREF_DEVICE_NAME);
        userInfo.deviceVersion = PreferencesUtils.ReadFromPreferencesString(context, userInfo.token + PREF_DEVICE_Version);
        userInfo.deviceBattery = PreferencesUtils.ReadFromPreferencesInt(context, userInfo.token + PREF_DEVICE_BATTERY);
        userInfo.Psd = PreferencesUtils.ReadFromPreferencesString(context, userInfo.token + PREF_Psd);
        userInfo.Account = PreferencesUtils.ReadFromPreferencesString(context, userInfo.token + PREF_Account);
        userInfo.AreaCode = PreferencesUtils.ReadFromPreferencesString(context, userInfo.token + PREF_AreaCode);
        userInfo.isRememberPassword = PreferencesUtils.ReadFromPreferencesBoolean(context, userInfo.token + PREF_isRememberPassword);
        userInfo.lastLoginType = PreferencesUtils.ReadFromPreferencesInt(context, userInfo.token + PREF_LastLoginType);
        userInfo.lastSyncTime = PreferencesUtils.ReadFromPreferencesLong(context, userInfo.token + PREF_LAST_SYNC_TIME);
        userInfo.hand = PreferencesUtils.ReadFromPreferencesInt(context, userInfo.token + PREF_HAND);
        userInfo.manner = PreferencesUtils.ReadFromPreferencesInt(context, userInfo.token + PREF_MANNER);
        userInfo.condition = PreferencesUtils.ReadFromPreferencesInt(context, userInfo.token + PREF_CONDITION);

        userInfo.clockSwitch1 = PreferencesUtils.ReadFromPreferencesBoolean(context, userInfo.token + PREF_NOTIFICATION_CLOCK1_SWITCH);
        userInfo.clockTime1 = PreferencesUtils.ReadFromPreferencesString(context, userInfo.token + PREF_NOTIFICATION_CLOCK1_TIME);
        userInfo.clockDayOfWeek1 = PreferencesUtils.ReadFromPreferencesInt(context, userInfo.token + PREF__NOTIFICATION_CLOCK1_DAY_OF_WEEK);

        userInfo.clockSwitch2 = PreferencesUtils.ReadFromPreferencesBoolean(context, userInfo.token + PREF_NOTIFICATION_CLOCK2_SWITCH);
        userInfo.clockTime2 = PreferencesUtils.ReadFromPreferencesString(context, userInfo.token + PREF_NOTIFICATION_CLOCK2_TIME);
        userInfo.clockDayOfWeek2 = PreferencesUtils.ReadFromPreferencesInt(context, userInfo.token + PREF__NOTIFICATION_CLOCK2_DAY_OF_WEEK);

        userInfo.clockSwitch3 = PreferencesUtils.ReadFromPreferencesBoolean(context, userInfo.token + PREF_NOTIFICATION_CLOCK3_SWITCH);
        userInfo.clockTime3 = PreferencesUtils.ReadFromPreferencesString(context, userInfo.token + PREF_NOTIFICATION_CLOCK3_TIME);
        userInfo.clockDayOfWeek3 = PreferencesUtils.ReadFromPreferencesInt(context, userInfo.token + PREF__NOTIFICATION_CLOCK3_DAY_OF_WEEK);

        userInfo.clockSwitch4 = PreferencesUtils.ReadFromPreferencesBoolean(context, userInfo.token + PREF_NOTIFICATION_CLOCK4_SWITCH);
        userInfo.clockTime4 = PreferencesUtils.ReadFromPreferencesString(context, userInfo.token + PREF_NOTIFICATION_CLOCK4_TIME);
        userInfo.clockDayOfWeek4 = PreferencesUtils.ReadFromPreferencesInt(context, userInfo.token + PREF__NOTIFICATION_CLOCK4_DAY_OF_WEEK);

        userInfo.brushTime = PreferencesUtils.ReadFromPreferencesInt(context, userInfo.token + PREF_BRUSH_TIME);
        userInfo.score = PreferencesUtils.ReadFromPreferencesInt(context, userInfo.token + PREF_SCORE);
        userInfo.changeHead = PreferencesUtils.ReadFromPreferencesLong(context, userInfo.token + PREF_CHANGE_HEAD);
        userInfo.collectLog = PreferencesUtils.ReadFromPreferencesBoolean(context, userInfo.token + PREF_COLLECT_LOG);
        userInfo.teethWhiteness = PreferencesUtils.ReadFromPreferencesInt(context, userInfo.token + PREF_TEETH_WHITENESS);
        userInfo.isFirstTimeDisplayPlaque = PreferencesUtils.ReadFromPreferencesBoolean(context,userInfo.token+PREF_IS_FIRST_TIME_DISPLAY_PAQUE);

        return userInfo;

    }

    public void SyncToLocal(Context context) {


        PreferencesUtils.WriteToPreferencesString(context, PREF_TOKEN, token);
        PreferencesUtils.WriteToPreferencesString(context, PREF_TOKEN + PREF_NICKNAME, nickName);
        PreferencesUtils.WriteToPreferencesInt(context, token + PREF_SEX, gender);
        PreferencesUtils.WriteToPreferencesString(context, token + PREF_BIRTHDAY, Util.FormDateTimeString2(birthday));
        PreferencesUtils.WriteToPreferencesString(context, token + PREF_HEADURL, headUrl);
        PreferencesUtils.WriteToPreferencesString(context, token + PREF_MAC, mac);
        PreferencesUtils.WriteToPreferencesInt(context, token + PREF_HAND, hand);
        PreferencesUtils.WriteToPreferencesInt(context, token + PREF_MANNER, manner);
        PreferencesUtils.WriteToPreferencesInt(context, token + PREF_CONDITION, condition);

        //DrinkNotification 0:enabled 1:disabled;
        PreferencesUtils.WriteToPreferencesBoolean(context, token + PREF_DRINKING_NOTIFICATION, drinkingNotification);
        //是否第一次进入APP
        PreferencesUtils.WriteToPreferencesBoolean(context, token + PREF_FIRST_TIME_IN_APP, isFirstTimeIntoAPP);

        PreferencesUtils.WriteToPreferencesString(context, token + PREF_DEVICE_NAME, deviceName);
        PreferencesUtils.WriteToPreferencesString(context, token + PREF_DEVICE_Version, deviceVersion);
        PreferencesUtils.WriteToPreferencesInt(context, token + PREF_DEVICE_BATTERY, deviceBattery);
        PreferencesUtils.WriteToPreferencesLong(context, token + PREF_LAST_SYNC_TIME, lastSyncTime);

        PreferencesUtils.WriteToPreferencesBoolean(context, token + PREF_NOTIFICATION_CLOCK1_SWITCH, clockSwitch1);
        PreferencesUtils.WriteToPreferencesString(context, token + PREF_NOTIFICATION_CLOCK1_TIME, clockTime1);
        PreferencesUtils.WriteToPreferencesInt(context, token + PREF__NOTIFICATION_CLOCK1_DAY_OF_WEEK, clockDayOfWeek1);

        PreferencesUtils.WriteToPreferencesBoolean(context, token + PREF_NOTIFICATION_CLOCK2_SWITCH, clockSwitch2);
        PreferencesUtils.WriteToPreferencesString(context, token + PREF_NOTIFICATION_CLOCK2_TIME, clockTime2);
        PreferencesUtils.WriteToPreferencesInt(context, token + PREF__NOTIFICATION_CLOCK2_DAY_OF_WEEK, clockDayOfWeek2);

        PreferencesUtils.WriteToPreferencesBoolean(context, token + PREF_NOTIFICATION_CLOCK3_SWITCH, clockSwitch3);
        PreferencesUtils.WriteToPreferencesString(context, token + PREF_NOTIFICATION_CLOCK3_TIME, clockTime3);
        PreferencesUtils.WriteToPreferencesInt(context, token + PREF__NOTIFICATION_CLOCK3_DAY_OF_WEEK, clockDayOfWeek3);

        PreferencesUtils.WriteToPreferencesBoolean(context, token + PREF_NOTIFICATION_CLOCK4_SWITCH, clockSwitch4);
        PreferencesUtils.WriteToPreferencesString(context, token + PREF_NOTIFICATION_CLOCK4_TIME, clockTime4);
        PreferencesUtils.WriteToPreferencesInt(context, token + PREF__NOTIFICATION_CLOCK4_DAY_OF_WEEK, clockDayOfWeek4);
        PreferencesUtils.WriteToPreferencesInt(context, token + PREF_BRUSH_TIME, brushTime);
        PreferencesUtils.WriteToPreferencesInt(context, token + PREF_SCORE, score);
        PreferencesUtils.WriteToPreferencesString(context, token + PREF_Psd, Psd);
        PreferencesUtils.WriteToPreferencesString(context, token + PREF_Account, Account);
        PreferencesUtils.WriteToPreferencesString(context, token + PREF_AreaCode, AreaCode);
        PreferencesUtils.WriteToPreferencesBoolean(context, token + PREF_isRememberPassword, isRememberPassword);
        PreferencesUtils.WriteToPreferencesInt(context, token + PREF_LastLoginType, lastLoginType);

        PreferencesUtils.WriteToPreferencesLong(context, token + PREF_CHANGE_HEAD, changeHead);
        PreferencesUtils.WriteToPreferencesBoolean(context, token + PREF_COLLECT_LOG, collectLog);
        PreferencesUtils.WriteToPreferencesInt(context, token + PREF_TEETH_WHITENESS, teethWhiteness);
        PreferencesUtils.WriteToPreferencesBoolean(context,token+PREF_IS_FIRST_TIME_DISPLAY_PAQUE,isFirstTimeDisplayPlaque);

    }

}
